package com.erpanderp.wam.tm.model.service;

import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.Session;

import com.erpanderp.wam.tm.model.entity.RRFManagerRecommendation;
import com.erpanderp.wam.util.HibernateUtil;

public class RRFManagerRecommendationDAO {
	
	public RRFManagerRecommendation createManagerRecommendation(RRFManagerRecommendation managerRecommendation){
		try{
		 Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		 session.beginTransaction();
		 session.setFlushMode(FlushMode.COMMIT);
		 session.saveOrUpdate(managerRecommendation);
		 session.getTransaction().commit();
		 System.out.println("=========DAO================"+managerRecommendation);
		 return managerRecommendation;	
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
		
	}
	
	 public RRFManagerRecommendation getRRFManagerRecomendationsByRRFCode(String rrfCode,Long recruitmentProfileId){
		 RRFManagerRecommendation rrfManagerRecommendation = new RRFManagerRecommendation();
		 	try{
		 		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		 		session.beginTransaction();
		 		session.setFlushMode(FlushMode.AUTO);
		 		String queryString = "from RRFManagerRecommendation mr where mr.recruitmentRequestCode = :rrfCode and mr.recruitmentProfile =:recruitmentProfileId";
		 		Query query = session.createQuery(queryString).setString("rrfCode", rrfCode).setLong("recruitmentProfileId", recruitmentProfileId);
		 		query.setCacheable(false);
		 		rrfManagerRecommendation = (RRFManagerRecommendation) query.uniqueResult();
		 		session.getTransaction().commit();
		 		return rrfManagerRecommendation;
		 	}catch (Exception e) {
		 		e.printStackTrace();
		 		return null;			
				}
		 	
		 }

}
